package cuit.demo.controller;

import cuit.demo.Entity.Article;
import cuit.demo.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private MyService myService;
    // 显示zhuye 页面
    @GetMapping("/index")
    public String index(Model model) {
        // 通过服务接口获取所有文章
        List<Article> articles = myService.findAllArticles();
        if (articles != null && !articles.isEmpty()) {
            model.addAttribute("articles", articles);
            System.out.println(model.getAttribute("user"));
        } else {
            model.addAttribute("articles", "暂无文章数据");
        }
        return "index";
    }
}